#pragma once

#include <entt/entt.hpp>
#include "./bundle.hpp"
#include "./event.hpp"
#include "./world.hpp"

namespace qbe::ecs {

class Query {
 public:
  World& _world;

 public:
  Query(World& world) : _world(world){};
  ~Query(){};

  entt::registry& get_reg();

  template <typename T>
  T& get_resource() {
    return _world.template resource<T>();
  }

  template <typename T>
  const T& get_resource() const {
    return _world.template resource<T>();
  }

  template <typename T>
  ecs::EventWriter<T> get_event_writer() {
    ecs::Event<T>& event = get_resource<ecs::Event<T>>();
    return ecs::EventWriter<T>(event, 0);
  }

  template <typename T>
  ecs::EventReader<T> get_event_reader() {
    ecs::Event<T>& event = get_resource<ecs::Event<T>>();
    return ecs::EventReader<T>(event);
  }

  // ecs::Bus& bus() { return _world.get_bus(); }

  template <typename T>
  T& get_component(entt::entity entity) {
    return _world.get_registry().template get<T>(entity);
  }

  template <typename T>
  const T& get_component(entt::entity entity) const {
    return _world.get_registry().template get<T>(entity);
  }
};

}  // namespace qbe::ecs